package net.janeluo.rs.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.janeluo.rs.entity.RS_Orders;
import net.janeluo.rs.entity.RS_User;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.sql.Criteria;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.service.Service;

/**
 * 个人中心业务类
 * 
 * @author DLK)JaneLuo
 * @version 1.0.0
 */
@IocBean(fields = { "dao" })
public class PersonalCenterService extends Service {
    private static final Log log = Logs.getLog(PersonalCenterService.class);

    public PersonalCenterService() {
        super();
    }

    public PersonalCenterService(Dao dao) {
        super(dao);
    }
    
    /**
     * 个人中心初始化查询
     * 
     * @return
     */
    public Map<String, Object> initPersonalCenter(String userid){
        log.debug("============= 个人中心初始化查询处理开始 =============");
        Map<String, Object> returnMap = new HashMap<String, Object>();
        RS_User user = dao().fetch(RS_User.class, Cnd.where("userid", "=", userid));
        returnMap.put("userinfo", user);
        
        // 我的订单列表
        Criteria cri = Cnd.cri();
        cri.where().andEquals("userid", userid);
        // 查询用户总订单数
        int orderCount = dao().count(RS_Orders.class, cri);
        returnMap.put("orderCount", orderCount);
        
        SimpleDateFormat sd = new SimpleDateFormat("yyyy/MM/dd");
        sd.format(new Date());
        // 查询订单列表
        cri.where().andLike("orderTime", sd.format(new Date()));
        List<RS_Orders> list = dao().fetchLinks(dao().query(RS_Orders.class, cri), "menu");
        returnMap.put("orderslst", list);
        
        log.debug("============= 个人中心初始化查询处理结束 =============");
        return returnMap;
    }
}
